class ApplicationController < ActionController::Base
  protect_from_forgery
  layout 'application'
  before_filter :set_user
  
  ################################USER##########################################
  protected
  def set_user
    @user = Users.find(session[:id]) if @user.nil? && session[:id]
  end

  def login_required
    return true if @user
    access_denied
    return false
  end

  def access_denied
    session[:return_to] = request.request_uri
    flash[:error] = 'Oops. You need to login before you can view that page.'
    redirect_to :controller => 'user', :action => 'login'
  end

  def chk_logged_in
    if @user
      flash[:message] = "You are already logged in"
      redirect_to :controller=>"task",:action => "list"
      return false
    end
  end
  ##############################################################################

end